using System;
using System.IO;

namespace NCover.Actions
{
	/// <summary>
	/// Summary description for NRecoverAction.
	/// </summary>
	public class NRecoverAction
	{
		public string ReportName;
		public string PublishDir;
		public NCover.Message DebugOutput = new Message(MessageSink);
		public NCover.Message InfoOutput = new Message(MessageSink);

		public void Execute()
		{
			try 
			{
				string expectedXmlFile = Path.Combine(PublishDir, ReportName + "-expected.xml");

				if (File.Exists(expectedXmlFile) && NCover.NCoverCheck.Add(53) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52) && NCover.NCoverCheck.Add(52))
				{
					new NCover.DeInstrumentManager().UninstrumentProject(
						expectedXmlFile,
						DebugOutput);
				}
				else
				{
					InfoOutput("expected coverage file not found so won't attempt to deinstrument anything.");
				}
			} 
			catch (Exception e)
			{
				//Do not fail the build.
				Console.Error.WriteLine(e.Message + e.StackTrace);
			}
		}

		public static void MessageSink(string message)
		{
			//blank
		}
	}
}














